class PositionMap {
	constructor() {
			this.map = new Map();
			this.positions = [];
	}

	setIndex(key , value , index = 0){
		if(this.positions.length - 1 > index) throw new Error("index 位置已越界")
		if (!this.map.has(key)) this.positions.splice(index , 0 , key)
		else {
			let posIndex = this.positions.findIndex( val => val == key)
			this.positions.splice(posIndex , 1)
			this.positions.splice(index , 0 , key)
		}
		return this.map.set(key, value);
	}

	set(key, value) {
			if (!this.map.has(key)) {
					this.positions.push(key);
			}
			return this.map.set(key, value);
	}

	get(key) {
			return this.map.get(key);
	}

	delete(key) {
			const position = this.positions.indexOf(key);
			if (position !== -1) {
					this.positions.splice(position, 1);
			}
			return this.map.delete(key);
	}

	keys() {
			return this.positions;
	}

	values() {
			return this.positions.map(key => this.map.get(key));
	}

	entries() {
			return this.positions.map(key => [key, this.map.get(key)]);
	}

	// 其他需要的Map方法可以类似添加
}

export default PositionMap


// 使用示例
// const positionMap = new PositionMap();
// positionMap.set('first', 'First Value');
// positionMap.set('second', 'Second Value');
// positionMap.set('third', 'Third Value');

// console.log(positionMap.keys()); // ['first', 'second', 'third']
// console.log(positionMap.values()); // ['First Value', 'Second Value', 'Third Value']
// console.log(positionMap.entries()); // [['first', 'First Value'], ['second', 'Second Value'], ['third', 'Third Value']]

// positionMap.delete('second');
// console.log(positionMap.entries()); // [['first', 'First Value'], ['third', 'Third Value']]